Practice Question 1

Home / Java Practice Question / Practice Question 1

Practice Question 1


Question 1. Find the number can be expressed as sum of two prime numbers. Print "yes" if it is sum of two prime numbers otherwise print "no".

Program


class Solution {

    static String isSumOfTwo(int N){

        if(N <= 3) {

            return "No";

        }

        if(N%2 == 0) {

            return "Yes";

        }

        N -= 2;

        for (int i = 2;i < N;i++) {

            if(N%i == 0) {

                return "No";

            }

        }

        return "Yes";

    }

}